﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace QLNHK.BLL
{
	public partial class DoiTuong_TienAn : Ent_Base, ICloneable
	{
        #region Variables
        
		private int _iD;
		private long _doiTuongID;
		private string _tienAn = string.Empty;
		private string _tienSu = string.Empty;
		private string _thuDoan = string.Empty;
		private string _dieuKien = string.Empty;
		private string _diaBanGayAns = string.Empty;
		private string _phamViHoatDongs = string.Empty;
		private int _doiTuongDanhMucID;
		private int _doiTuongHeID;
		private int _doiTuongPhanLoaiID;
		private string _thoiGianPhanLoai = string.Empty;
		private string _noiLapHoSo = string.Empty;
		private DateTime _ngayLapHoSo = new DateTime(1753, 1, 1);
		private string _soDangKy = string.Empty;
		private DateTime _ngayDangKy = new DateTime(1753, 1, 1);
		private DateTime _ngayKetThuc = new DateTime(1753, 1, 1);
		private bool _ketThucQuanLy;
		private string _bienPhapQuanLy = string.Empty;
		private int _canBoQuanLyID;
        
        #endregion
    
        //---------------------------------------------------------------------------------------------
        
		#region Properties.
		
		public int ID 
        { 
            get { return  _iD; } 
            set
            {
                _iD = value;
                OnPropertyChanged("ID");
            }
        }
		public long DoiTuongID 
        { 
            get { return  _doiTuongID; } 
            set
            {
                _doiTuongID = value;
                OnPropertyChanged("DoiTuongID");
            }
        }
		public string TienAn 
        { 
            get { return  _tienAn; } 
            set
            {
                _tienAn = value;
                OnPropertyChanged("TienAn");
            }
        }
		public string TienSu 
        { 
            get { return  _tienSu; } 
            set
            {
                _tienSu = value;
                OnPropertyChanged("TienSu");
            }
        }
		public string ThuDoan 
        { 
            get { return  _thuDoan; } 
            set
            {
                _thuDoan = value;
                OnPropertyChanged("ThuDoan");
            }
        }
		public string DieuKien 
        { 
            get { return  _dieuKien; } 
            set
            {
                _dieuKien = value;
                OnPropertyChanged("DieuKien");
            }
        }
		public string DiaBanGayAns 
        { 
            get { return  _diaBanGayAns; } 
            set
            {
                _diaBanGayAns = value;
                OnPropertyChanged("DiaBanGayAns");
            }
        }
		public string PhamViHoatDongs 
        { 
            get { return  _phamViHoatDongs; } 
            set
            {
                _phamViHoatDongs = value;
                OnPropertyChanged("PhamViHoatDongs");
            }
        }
		public int DoiTuongDanhMucID 
        { 
            get { return  _doiTuongDanhMucID; } 
            set
            {
                _doiTuongDanhMucID = value;
                OnPropertyChanged("DoiTuongDanhMucID");
            }
        }
		public int DoiTuongHeID 
        { 
            get { return  _doiTuongHeID; } 
            set
            {
                _doiTuongHeID = value;
                OnPropertyChanged("DoiTuongHeID");
            }
        }
		public int DoiTuongPhanLoaiID 
        { 
            get { return  _doiTuongPhanLoaiID; } 
            set
            {
                _doiTuongPhanLoaiID = value;
                OnPropertyChanged("DoiTuongPhanLoaiID");
            }
        }
		public string ThoiGianPhanLoai 
        { 
            get { return  _thoiGianPhanLoai; } 
            set
            {
                _thoiGianPhanLoai = value;
                OnPropertyChanged("ThoiGianPhanLoai");
            }
        }
		public string NoiLapHoSo 
        { 
            get { return  _noiLapHoSo; } 
            set
            {
                _noiLapHoSo = value;
                OnPropertyChanged("NoiLapHoSo");
            }
        }
		public DateTime NgayLapHoSo 
        { 
            get { return  _ngayLapHoSo; } 
            set
            {
                _ngayLapHoSo = value;
                OnPropertyChanged("NgayLapHoSo");
            }
        }
		public string SoDangKy 
        { 
            get { return  _soDangKy; } 
            set
            {
                _soDangKy = value;
                OnPropertyChanged("SoDangKy");
            }
        }
		public DateTime NgayDangKy 
        { 
            get { return  _ngayDangKy; } 
            set
            {
                _ngayDangKy = value;
                OnPropertyChanged("NgayDangKy");
            }
        }
		public DateTime NgayKetThuc 
        { 
            get { return  _ngayKetThuc; } 
            set
            {
                _ngayKetThuc = value;
                OnPropertyChanged("NgayKetThuc");
            }
        }
		public bool KetThucQuanLy 
        { 
            get { return  _ketThucQuanLy; } 
            set
            {
                _ketThucQuanLy = value;
                OnPropertyChanged("KetThucQuanLy");
            }
        }
		public string BienPhapQuanLy 
        { 
            get { return  _bienPhapQuanLy; } 
            set
            {
                _bienPhapQuanLy = value;
                OnPropertyChanged("BienPhapQuanLy");
            }
        }
		public int CanBoQuanLyID 
        { 
            get { return  _canBoQuanLyID; } 
            set
            {
                _canBoQuanLyID = value;
                OnPropertyChanged("CanBoQuanLyID");
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Methods
		protected static List<DoiTuong_TienAn> ConvertToCollection(IDataReader reader)
		{
			List<DoiTuong_TienAn> collection = new List<DoiTuong_TienAn>();
			while (reader.Read())
			{
				DoiTuong_TienAn entity = new DoiTuong_TienAn();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("DoiTuongID"))) entity.DoiTuongID = reader.GetInt64(reader.GetOrdinal("DoiTuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TienAn"))) entity.TienAn = reader.GetString(reader.GetOrdinal("TienAn"));
				if (!reader.IsDBNull(reader.GetOrdinal("TienSu"))) entity.TienSu = reader.GetString(reader.GetOrdinal("TienSu"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuDoan"))) entity.ThuDoan = reader.GetString(reader.GetOrdinal("ThuDoan"));
				if (!reader.IsDBNull(reader.GetOrdinal("DieuKien"))) entity.DieuKien = reader.GetString(reader.GetOrdinal("DieuKien"));
				if (!reader.IsDBNull(reader.GetOrdinal("DiaBanGayAns"))) entity.DiaBanGayAns = reader.GetString(reader.GetOrdinal("DiaBanGayAns"));
				if (!reader.IsDBNull(reader.GetOrdinal("PhamViHoatDongs"))) entity.PhamViHoatDongs = reader.GetString(reader.GetOrdinal("PhamViHoatDongs"));
				if (!reader.IsDBNull(reader.GetOrdinal("DoiTuongDanhMucID"))) entity.DoiTuongDanhMucID = reader.GetInt32(reader.GetOrdinal("DoiTuongDanhMucID"));
				if (!reader.IsDBNull(reader.GetOrdinal("DoiTuongHeID"))) entity.DoiTuongHeID = reader.GetInt32(reader.GetOrdinal("DoiTuongHeID"));
				if (!reader.IsDBNull(reader.GetOrdinal("DoiTuongPhanLoaiID"))) entity.DoiTuongPhanLoaiID = reader.GetInt32(reader.GetOrdinal("DoiTuongPhanLoaiID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThoiGianPhanLoai"))) entity.ThoiGianPhanLoai = reader.GetString(reader.GetOrdinal("ThoiGianPhanLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiLapHoSo"))) entity.NoiLapHoSo = reader.GetString(reader.GetOrdinal("NoiLapHoSo"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayLapHoSo"))) entity.NgayLapHoSo = reader.GetDateTime(reader.GetOrdinal("NgayLapHoSo"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoDangKy"))) entity.SoDangKy = reader.GetString(reader.GetOrdinal("SoDangKy"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayDangKy"))) entity.NgayDangKy = reader.GetDateTime(reader.GetOrdinal("NgayDangKy"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayKetThuc"))) entity.NgayKetThuc = reader.GetDateTime(reader.GetOrdinal("NgayKetThuc"));
				if (!reader.IsDBNull(reader.GetOrdinal("KetThucQuanLy"))) entity.KetThucQuanLy = reader.GetBoolean(reader.GetOrdinal("KetThucQuanLy"));
				if (!reader.IsDBNull(reader.GetOrdinal("BienPhapQuanLy"))) entity.BienPhapQuanLy = reader.GetString(reader.GetOrdinal("BienPhapQuanLy"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoQuanLyID"))) entity.CanBoQuanLyID = reader.GetInt32(reader.GetOrdinal("CanBoQuanLyID"));
				collection.Add(entity);
			}
			reader.Close();
			return collection;
		}
		
		public static bool Find(List<DoiTuong_TienAn> collection, int iD)
        {
            foreach (DoiTuong_TienAn item in collection)
            {
                if (item.ID == iD)
                {
                    return true;
                }
            }

            return false;
        }
		
		public static void UpdateDataSet(DataSet ds)
        {
            string insert = "Insert INTO t_DoiTuong_TienAn VALUES(@DoiTuongID, @TienAn, @TienSu, @ThuDoan, @DieuKien, @DiaBanGayAns, @PhamViHoatDongs, @DoiTuongDanhMucID, @DoiTuongHeID, @DoiTuongPhanLoaiID, @ThoiGianPhanLoai, @NoiLapHoSo, @NgayLapHoSo, @SoDangKy, @NgayDangKy, @NgayKetThuc, @KetThucQuanLy, @BienPhapQuanLy, @CanBoQuanLyID)";
            string update = "UPDATE t_DoiTuong_TienAn SET DoiTuongID = @DoiTuongID, TienAn = @TienAn, TienSu = @TienSu, ThuDoan = @ThuDoan, DieuKien = @DieuKien, DiaBanGayAns = @DiaBanGayAns, PhamViHoatDongs = @PhamViHoatDongs, DoiTuongDanhMucID = @DoiTuongDanhMucID, DoiTuongHeID = @DoiTuongHeID, DoiTuongPhanLoaiID = @DoiTuongPhanLoaiID, ThoiGianPhanLoai = @ThoiGianPhanLoai, NoiLapHoSo = @NoiLapHoSo, NgayLapHoSo = @NgayLapHoSo, SoDangKy = @SoDangKy, NgayDangKy = @NgayDangKy, NgayKetThuc = @NgayKetThuc, KetThucQuanLy = @KetThucQuanLy, BienPhapQuanLy = @BienPhapQuanLy, CanBoQuanLyID = @CanBoQuanLyID WHERE ID = @ID";
            string delete = "DELETE FROM t_DoiTuong_TienAn WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongID", SqlDbType.BigInt, "DoiTuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TienAn", SqlDbType.NVarChar, "TienAn", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TienSu", SqlDbType.NVarChar, "TienSu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuDoan", SqlDbType.NVarChar, "ThuDoan", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DieuKien", SqlDbType.NVarChar, "DieuKien", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DiaBanGayAns", SqlDbType.VarChar, "DiaBanGayAns", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@PhamViHoatDongs", SqlDbType.VarChar, "PhamViHoatDongs", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongDanhMucID", SqlDbType.Int, "DoiTuongDanhMucID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongHeID", SqlDbType.Int, "DoiTuongHeID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, "DoiTuongPhanLoaiID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, "ThoiGianPhanLoai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiLapHoSo", SqlDbType.NVarChar, "NoiLapHoSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayLapHoSo", SqlDbType.DateTime, "NgayLapHoSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDangKy", SqlDbType.NVarChar, "SoDangKy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayDangKy", SqlDbType.DateTime, "NgayDangKy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayKetThuc", SqlDbType.DateTime, "NgayKetThuc", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@KetThucQuanLy", SqlDbType.Bit, "KetThucQuanLy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, "BienPhapQuanLy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongID", SqlDbType.BigInt, "DoiTuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TienAn", SqlDbType.NVarChar, "TienAn", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TienSu", SqlDbType.NVarChar, "TienSu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuDoan", SqlDbType.NVarChar, "ThuDoan", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DieuKien", SqlDbType.NVarChar, "DieuKien", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DiaBanGayAns", SqlDbType.VarChar, "DiaBanGayAns", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@PhamViHoatDongs", SqlDbType.VarChar, "PhamViHoatDongs", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongDanhMucID", SqlDbType.Int, "DoiTuongDanhMucID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongHeID", SqlDbType.Int, "DoiTuongHeID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, "DoiTuongPhanLoaiID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, "ThoiGianPhanLoai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiLapHoSo", SqlDbType.NVarChar, "NoiLapHoSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayLapHoSo", SqlDbType.DateTime, "NgayLapHoSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDangKy", SqlDbType.NVarChar, "SoDangKy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayDangKy", SqlDbType.DateTime, "NgayDangKy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayKetThuc", SqlDbType.DateTime, "NgayKetThuc", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@KetThucQuanLy", SqlDbType.Bit, "KetThucQuanLy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, "BienPhapQuanLy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, ds.Tables[0].TableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }
				
		public static void UpdateDataSet(DataSet ds, string tableName)
        {
            string insert = "Insert INTO t_DoiTuong_TienAn VALUES(@DoiTuongID, @TienAn, @TienSu, @ThuDoan, @DieuKien, @DiaBanGayAns, @PhamViHoatDongs, @DoiTuongDanhMucID, @DoiTuongHeID, @DoiTuongPhanLoaiID, @ThoiGianPhanLoai, @NoiLapHoSo, @NgayLapHoSo, @SoDangKy, @NgayDangKy, @NgayKetThuc, @KetThucQuanLy, @BienPhapQuanLy, @CanBoQuanLyID)";
            string update = "UPDATE t_DoiTuong_TienAn SET DoiTuongID = @DoiTuongID, TienAn = @TienAn, TienSu = @TienSu, ThuDoan = @ThuDoan, DieuKien = @DieuKien, DiaBanGayAns = @DiaBanGayAns, PhamViHoatDongs = @PhamViHoatDongs, DoiTuongDanhMucID = @DoiTuongDanhMucID, DoiTuongHeID = @DoiTuongHeID, DoiTuongPhanLoaiID = @DoiTuongPhanLoaiID, ThoiGianPhanLoai = @ThoiGianPhanLoai, NoiLapHoSo = @NoiLapHoSo, NgayLapHoSo = @NgayLapHoSo, SoDangKy = @SoDangKy, NgayDangKy = @NgayDangKy, NgayKetThuc = @NgayKetThuc, KetThucQuanLy = @KetThucQuanLy, BienPhapQuanLy = @BienPhapQuanLy, CanBoQuanLyID = @CanBoQuanLyID WHERE ID = @ID";
            string delete = "DELETE FROM t_DoiTuong_TienAn WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongID", SqlDbType.BigInt, "DoiTuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TienAn", SqlDbType.NVarChar, "TienAn", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TienSu", SqlDbType.NVarChar, "TienSu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuDoan", SqlDbType.NVarChar, "ThuDoan", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DieuKien", SqlDbType.NVarChar, "DieuKien", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DiaBanGayAns", SqlDbType.VarChar, "DiaBanGayAns", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@PhamViHoatDongs", SqlDbType.VarChar, "PhamViHoatDongs", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongDanhMucID", SqlDbType.Int, "DoiTuongDanhMucID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongHeID", SqlDbType.Int, "DoiTuongHeID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, "DoiTuongPhanLoaiID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, "ThoiGianPhanLoai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiLapHoSo", SqlDbType.NVarChar, "NoiLapHoSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayLapHoSo", SqlDbType.DateTime, "NgayLapHoSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDangKy", SqlDbType.NVarChar, "SoDangKy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayDangKy", SqlDbType.DateTime, "NgayDangKy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayKetThuc", SqlDbType.DateTime, "NgayKetThuc", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@KetThucQuanLy", SqlDbType.Bit, "KetThucQuanLy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, "BienPhapQuanLy", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongID", SqlDbType.BigInt, "DoiTuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TienAn", SqlDbType.NVarChar, "TienAn", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TienSu", SqlDbType.NVarChar, "TienSu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuDoan", SqlDbType.NVarChar, "ThuDoan", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DieuKien", SqlDbType.NVarChar, "DieuKien", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DiaBanGayAns", SqlDbType.VarChar, "DiaBanGayAns", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@PhamViHoatDongs", SqlDbType.VarChar, "PhamViHoatDongs", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongDanhMucID", SqlDbType.Int, "DoiTuongDanhMucID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongHeID", SqlDbType.Int, "DoiTuongHeID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, "DoiTuongPhanLoaiID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, "ThoiGianPhanLoai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiLapHoSo", SqlDbType.NVarChar, "NoiLapHoSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayLapHoSo", SqlDbType.DateTime, "NgayLapHoSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDangKy", SqlDbType.NVarChar, "SoDangKy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayDangKy", SqlDbType.DateTime, "NgayDangKy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayKetThuc", SqlDbType.DateTime, "NgayKetThuc", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@KetThucQuanLy", SqlDbType.Bit, "KetThucQuanLy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, "BienPhapQuanLy", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, tableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static DoiTuong_TienAn Load(int iD)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_Load.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, iD);
            IDataReader reader = db.ExecuteReader(dbCommand);
			List<DoiTuong_TienAn> collection = ConvertToCollection(reader);	
			if (collection.Count > 0)
			{
				return collection[0];
			}
			return null;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<DoiTuong_TienAn> SelectCollectionAll()
		{
			IDataReader reader = SelectReaderAll();
			return ConvertToCollection(reader);			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<DoiTuong_TienAn> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			return ConvertToCollection(reader);		
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static List<DoiTuong_TienAn> SelectCollectionBy_DoiTuongID(long doiTuongID)
		{
            IDataReader reader = SelectReaderBy_DoiTuongID(doiTuongID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<DoiTuong_TienAn> SelectCollectionBy_DoiTuongDanhMucID(int doiTuongDanhMucID)
		{
            IDataReader reader = SelectReaderBy_DoiTuongDanhMucID(doiTuongDanhMucID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<DoiTuong_TienAn> SelectCollectionBy_DoiTuongHeID(int doiTuongHeID)
		{
            IDataReader reader = SelectReaderBy_DoiTuongHeID(doiTuongHeID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<DoiTuong_TienAn> SelectCollectionBy_DoiTuongPhanLoaiID(int doiTuongPhanLoaiID)
		{
            IDataReader reader = SelectReaderBy_DoiTuongPhanLoaiID(doiTuongPhanLoaiID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectBy_DoiTuongID(long doiTuongID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, doiTuongID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_DoiTuongDanhMucID(int doiTuongDanhMucID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongDanhMucID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, doiTuongDanhMucID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_DoiTuongHeID(int doiTuongHeID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongHeID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, doiTuongHeID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_DoiTuongPhanLoaiID(int doiTuongPhanLoaiID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongPhanLoaiID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, doiTuongPhanLoaiID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_DoiTuong_TienAn_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DoiTuong_TienAn_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_DoiTuong_TienAn_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DoiTuong_TienAn_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static IDataReader SelectReaderBy_DoiTuongID(long doiTuongID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, doiTuongID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_DoiTuongDanhMucID(int doiTuongDanhMucID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongDanhMucID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, doiTuongDanhMucID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_DoiTuongHeID(int doiTuongHeID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongHeID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, doiTuongHeID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_DoiTuongPhanLoaiID(int doiTuongPhanLoaiID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_SelectBy_DoiTuongPhanLoaiID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, doiTuongPhanLoaiID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int InsertDoiTuong_TienAn(long doiTuongID, string tienAn, string tienSu, string thuDoan, string dieuKien, string diaBanGayAns, string phamViHoatDongs, int doiTuongDanhMucID, int doiTuongHeID, int doiTuongPhanLoaiID, string thoiGianPhanLoai, string noiLapHoSo, DateTime ngayLapHoSo, string soDangKy, DateTime ngayDangKy, DateTime ngayKetThuc, bool ketThucQuanLy, string bienPhapQuanLy, int canBoQuanLyID)
		{
			DoiTuong_TienAn entity = new DoiTuong_TienAn();	
			entity.DoiTuongID = doiTuongID;
			entity.TienAn = tienAn;
			entity.TienSu = tienSu;
			entity.ThuDoan = thuDoan;
			entity.DieuKien = dieuKien;
			entity.DiaBanGayAns = diaBanGayAns;
			entity.PhamViHoatDongs = phamViHoatDongs;
			entity.DoiTuongDanhMucID = doiTuongDanhMucID;
			entity.DoiTuongHeID = doiTuongHeID;
			entity.DoiTuongPhanLoaiID = doiTuongPhanLoaiID;
			entity.ThoiGianPhanLoai = thoiGianPhanLoai;
			entity.NoiLapHoSo = noiLapHoSo;
			entity.NgayLapHoSo = ngayLapHoSo;
			entity.SoDangKy = soDangKy;
			entity.NgayDangKy = ngayDangKy;
			entity.NgayKetThuc = ngayKetThuc;
			entity.KetThucQuanLy = ketThucQuanLy;
			entity.BienPhapQuanLy = bienPhapQuanLy;
			entity.CanBoQuanLyID = canBoQuanLyID;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_DoiTuong_TienAn_Insert.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.Int, 4);
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, DoiTuongID);
			db.AddInParameter(dbCommand, "@TienAn", SqlDbType.NVarChar, TienAn);
			db.AddInParameter(dbCommand, "@TienSu", SqlDbType.NVarChar, TienSu);
			db.AddInParameter(dbCommand, "@ThuDoan", SqlDbType.NVarChar, ThuDoan);
			db.AddInParameter(dbCommand, "@DieuKien", SqlDbType.NVarChar, DieuKien);
			db.AddInParameter(dbCommand, "@DiaBanGayAns", SqlDbType.VarChar, DiaBanGayAns);
			db.AddInParameter(dbCommand, "@PhamViHoatDongs", SqlDbType.VarChar, PhamViHoatDongs);
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, DoiTuongDanhMucID);
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, DoiTuongHeID);
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, DoiTuongPhanLoaiID);
			db.AddInParameter(dbCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, ThoiGianPhanLoai);
			db.AddInParameter(dbCommand, "@NoiLapHoSo", SqlDbType.NVarChar, NoiLapHoSo);
			db.AddInParameter(dbCommand, "@NgayLapHoSo", SqlDbType.DateTime, NgayLapHoSo.Year <= 1753 ? DBNull.Value : (object) NgayLapHoSo);
			db.AddInParameter(dbCommand, "@SoDangKy", SqlDbType.NVarChar, SoDangKy);
			db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, NgayDangKy.Year <= 1753 ? DBNull.Value : (object) NgayDangKy);
			db.AddInParameter(dbCommand, "@NgayKetThuc", SqlDbType.DateTime, NgayKetThuc.Year <= 1753 ? DBNull.Value : (object) NgayKetThuc);
			db.AddInParameter(dbCommand, "@KetThucQuanLy", SqlDbType.Bit, KetThucQuanLy);
			db.AddInParameter(dbCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, BienPhapQuanLy);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(List<DoiTuong_TienAn> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong_TienAn item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateDoiTuong_TienAn(int iD, long doiTuongID, string tienAn, string tienSu, string thuDoan, string dieuKien, string diaBanGayAns, string phamViHoatDongs, int doiTuongDanhMucID, int doiTuongHeID, int doiTuongPhanLoaiID, string thoiGianPhanLoai, string noiLapHoSo, DateTime ngayLapHoSo, string soDangKy, DateTime ngayDangKy, DateTime ngayKetThuc, bool ketThucQuanLy, string bienPhapQuanLy, int canBoQuanLyID)
		{
			DoiTuong_TienAn entity = new DoiTuong_TienAn();			
			entity.ID = iD;
			entity.DoiTuongID = doiTuongID;
			entity.TienAn = tienAn;
			entity.TienSu = tienSu;
			entity.ThuDoan = thuDoan;
			entity.DieuKien = dieuKien;
			entity.DiaBanGayAns = diaBanGayAns;
			entity.PhamViHoatDongs = phamViHoatDongs;
			entity.DoiTuongDanhMucID = doiTuongDanhMucID;
			entity.DoiTuongHeID = doiTuongHeID;
			entity.DoiTuongPhanLoaiID = doiTuongPhanLoaiID;
			entity.ThoiGianPhanLoai = thoiGianPhanLoai;
			entity.NoiLapHoSo = noiLapHoSo;
			entity.NgayLapHoSo = ngayLapHoSo;
			entity.SoDangKy = soDangKy;
			entity.NgayDangKy = ngayDangKy;
			entity.NgayKetThuc = ngayKetThuc;
			entity.KetThucQuanLy = ketThucQuanLy;
			entity.BienPhapQuanLy = bienPhapQuanLy;
			entity.CanBoQuanLyID = canBoQuanLyID;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "[dbo].p_DoiTuong_TienAn_InsertUpdate.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, DoiTuongID);
			db.AddInParameter(dbCommand, "@TienAn", SqlDbType.NVarChar, TienAn);
			db.AddInParameter(dbCommand, "@TienSu", SqlDbType.NVarChar, TienSu);
			db.AddInParameter(dbCommand, "@ThuDoan", SqlDbType.NVarChar, ThuDoan);
			db.AddInParameter(dbCommand, "@DieuKien", SqlDbType.NVarChar, DieuKien);
			db.AddInParameter(dbCommand, "@DiaBanGayAns", SqlDbType.VarChar, DiaBanGayAns);
			db.AddInParameter(dbCommand, "@PhamViHoatDongs", SqlDbType.VarChar, PhamViHoatDongs);
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, DoiTuongDanhMucID);
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, DoiTuongHeID);
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, DoiTuongPhanLoaiID);
			db.AddInParameter(dbCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, ThoiGianPhanLoai);
			db.AddInParameter(dbCommand, "@NoiLapHoSo", SqlDbType.NVarChar, NoiLapHoSo);
			db.AddInParameter(dbCommand, "@NgayLapHoSo", SqlDbType.DateTime, NgayLapHoSo.Year <= 1753 ? DBNull.Value : (object) NgayLapHoSo);
			db.AddInParameter(dbCommand, "@SoDangKy", SqlDbType.NVarChar, SoDangKy);
			db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, NgayDangKy.Year <= 1753 ? DBNull.Value : (object) NgayDangKy);
			db.AddInParameter(dbCommand, "@NgayKetThuc", SqlDbType.DateTime, NgayKetThuc.Year <= 1753 ? DBNull.Value : (object) NgayKetThuc);
			db.AddInParameter(dbCommand, "@KetThucQuanLy", SqlDbType.Bit, KetThucQuanLy);
			db.AddInParameter(dbCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, BienPhapQuanLy);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(List<DoiTuong_TienAn> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong_TienAn item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateDoiTuong_TienAn(int iD, long doiTuongID, string tienAn, string tienSu, string thuDoan, string dieuKien, string diaBanGayAns, string phamViHoatDongs, int doiTuongDanhMucID, int doiTuongHeID, int doiTuongPhanLoaiID, string thoiGianPhanLoai, string noiLapHoSo, DateTime ngayLapHoSo, string soDangKy, DateTime ngayDangKy, DateTime ngayKetThuc, bool ketThucQuanLy, string bienPhapQuanLy, int canBoQuanLyID)
		{
			DoiTuong_TienAn entity = new DoiTuong_TienAn();			
			entity.ID = iD;
			entity.DoiTuongID = doiTuongID;
			entity.TienAn = tienAn;
			entity.TienSu = tienSu;
			entity.ThuDoan = thuDoan;
			entity.DieuKien = dieuKien;
			entity.DiaBanGayAns = diaBanGayAns;
			entity.PhamViHoatDongs = phamViHoatDongs;
			entity.DoiTuongDanhMucID = doiTuongDanhMucID;
			entity.DoiTuongHeID = doiTuongHeID;
			entity.DoiTuongPhanLoaiID = doiTuongPhanLoaiID;
			entity.ThoiGianPhanLoai = thoiGianPhanLoai;
			entity.NoiLapHoSo = noiLapHoSo;
			entity.NgayLapHoSo = ngayLapHoSo;
			entity.SoDangKy = soDangKy;
			entity.NgayDangKy = ngayDangKy;
			entity.NgayKetThuc = ngayKetThuc;
			entity.KetThucQuanLy = ketThucQuanLy;
			entity.BienPhapQuanLy = bienPhapQuanLy;
			entity.CanBoQuanLyID = canBoQuanLyID;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_Update.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, DoiTuongID);
			db.AddInParameter(dbCommand, "@TienAn", SqlDbType.NVarChar, TienAn);
			db.AddInParameter(dbCommand, "@TienSu", SqlDbType.NVarChar, TienSu);
			db.AddInParameter(dbCommand, "@ThuDoan", SqlDbType.NVarChar, ThuDoan);
			db.AddInParameter(dbCommand, "@DieuKien", SqlDbType.NVarChar, DieuKien);
			db.AddInParameter(dbCommand, "@DiaBanGayAns", SqlDbType.VarChar, DiaBanGayAns);
			db.AddInParameter(dbCommand, "@PhamViHoatDongs", SqlDbType.VarChar, PhamViHoatDongs);
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, DoiTuongDanhMucID);
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, DoiTuongHeID);
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, DoiTuongPhanLoaiID);
			db.AddInParameter(dbCommand, "@ThoiGianPhanLoai", SqlDbType.NVarChar, ThoiGianPhanLoai);
			db.AddInParameter(dbCommand, "@NoiLapHoSo", SqlDbType.NVarChar, NoiLapHoSo);
			db.AddInParameter(dbCommand, "@NgayLapHoSo", SqlDbType.DateTime, NgayLapHoSo.Year <= 1753 ? DBNull.Value : (object) NgayLapHoSo);
			db.AddInParameter(dbCommand, "@SoDangKy", SqlDbType.NVarChar, SoDangKy);
			db.AddInParameter(dbCommand, "@NgayDangKy", SqlDbType.DateTime, NgayDangKy.Year <= 1753 ? DBNull.Value : (object) NgayDangKy);
			db.AddInParameter(dbCommand, "@NgayKetThuc", SqlDbType.DateTime, NgayKetThuc.Year <= 1753 ? DBNull.Value : (object) NgayKetThuc);
			db.AddInParameter(dbCommand, "@KetThucQuanLy", SqlDbType.Bit, KetThucQuanLy);
			db.AddInParameter(dbCommand, "@BienPhapQuanLy", SqlDbType.NVarChar, BienPhapQuanLy);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(List<DoiTuong_TienAn> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong_TienAn item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteDoiTuong_TienAn(int iD)
		{
			DoiTuong_TienAn entity = new DoiTuong_TienAn();
			entity.ID = iD;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_Delete.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static int DeleteBy_DoiTuongID(long doiTuongID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_DeleteBy_DoiTuongID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongID", SqlDbType.BigInt, doiTuongID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_DoiTuongDanhMucID(int doiTuongDanhMucID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_DeleteBy_DoiTuongDanhMucID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongDanhMucID", SqlDbType.Int, doiTuongDanhMucID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_DoiTuongHeID(int doiTuongHeID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_DeleteBy_DoiTuongHeID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongHeID", SqlDbType.Int, doiTuongHeID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_DoiTuongPhanLoaiID(int doiTuongPhanLoaiID)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_DeleteBy_DoiTuongPhanLoaiID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DoiTuongPhanLoaiID", SqlDbType.Int, doiTuongPhanLoaiID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		
		public static int DeleteDynamic(string whereCondition)
		{
			const string spName = "[dbo].[p_DoiTuong_TienAn_DeleteDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            
            return db.ExecuteNonQuery(dbCommand);   
		}
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(List<DoiTuong_TienAn> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong_TienAn item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
		
        //---------------------------------------------------------------------------------------------
		
        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public DoiTuong_TienAn CloneObject()
        {
            return this.Clone() as DoiTuong_TienAn;
        }
        
        #endregion
	}	
}